import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import '../../../config.dart';
import '../../../core/comments/custom_app_bar.dart';
import '../../../model/user_info/user_info_model.dart';
import '../../../viewmodel/home/friend_info/friend_info_view_model.dart';

class FriendInfoPage extends StatefulWidget {
  final UserInfo friendInfo;
  const FriendInfoPage({super.key, required this.friendInfo});
  @override
  _FriendInfoPage createState() => _FriendInfoPage();
}

class _FriendInfoPage extends State<FriendInfoPage> {
  @override
  Widget build(BuildContext context) {
    final friendInfo = widget.friendInfo;
    final vm = context.watch<FriendInfoViewModel>();
    return Scaffold(
      appBar: const CustomAppBar(),
      body: Column(
        children: [
          Container(
            height: 100,
            padding: const EdgeInsets.symmetric(vertical: 15, horizontal: 10),
            child: Container(
              decoration: const BoxDecoration(
                border: Border(
                  bottom: BorderSide(
                    color: Color(0xFFF6F0FA), // 边框颜色
                    width: 1.0, // 边框宽度
                  ),
                ),
              ),
              child: Row(
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  Container(
                    width: 55,
                    height: 55,
                    margin: const EdgeInsets.only(right: 20),
                    decoration: BoxDecoration(
                      image: DecorationImage(
                        image: NetworkImage(Config.baseUrl + friendInfo.avatar),
                        fit: BoxFit.cover,
                      ),
                      borderRadius: BorderRadius.circular(8),
                    ),
                  ),
                  Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    mainAxisSize: MainAxisSize.min,
                    children: [
                      Row(
                        children: [
                          Text(
                            friendInfo.username,
                            style: const TextStyle(
                              fontWeight: FontWeight.bold,
                              fontSize: 22,
                            ),
                          ),
                          Icon(
                            friendInfo.sex == 'MALE'
                                ? Icons.male
                                : Icons.female,
                            color: friendInfo.sex == 'MALE'
                                ? Colors.blue
                                : Colors.pink,
                            size: 20,
                          ),
                        ],
                      ),
                      Text(
                        'IM号: ${friendInfo.imId}',
                        style: const TextStyle(fontSize: 13),
                      )
                    ],
                  )
                ],
              ),
            ),
          ),
          ElevatedButton(
            onPressed: (){
              vm.addFriend(friendInfo.imId);
            },
            style: ElevatedButton.styleFrom(
              backgroundColor: const Color(0xFFFEF5FF),
              elevation: 0,
              shadowColor: Colors.transparent,
              shape: const RoundedRectangleBorder(borderRadius: BorderRadius.zero),
              minimumSize: const Size(double.infinity, 50),
            ).copyWith(
              overlayColor: WidgetStateProperty.resolveWith<Color?>(
                (Set<WidgetState> states) {
                  if (states.contains(WidgetState.pressed)) return const Color(0xFFF7F0FA);
                  return null;
                },
              ),
              elevation: WidgetStateProperty.all(0),
              shadowColor: WidgetStateProperty.all(Colors.transparent),
            ),
            child: const Text('添加通讯录'),
          )
        ],
      ),
    );
  }
}
